﻿Imports System.Globalization

Partial Public Class Online_Payment
    Inherits System.Web.UI.Page

    Dim clsFc As New ClassFunction
    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (IsPostBack) Then
            Dim lbPage As Label = CType(Master.FindControl("lbPage"), Label)
            lbPage.Text = "ONLINE PAYMENT "
            Try
                LoadPayment()
            Catch ex As Exception
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('คุณไม่มีสิทธิ์ในการใช้งานเมนูนี้ !!');", True)
                Response.Redirect("../Form/Logon.aspx", True)
            End Try

        End If
    End Sub

    Private Sub LoadPayment()
        ViewState("Payment") = clsGet.Get_BookingPayment(CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Customer_no") & "")
        If CType(ViewState("Payment"), DataSet).Tables(0).Rows.Count = 0 Then
            panelGridItem.Visible = False
            lbAlert.Visible = True
            lbAlert.Text = "ไม่พบรายการที่ต้องทำการชำระค่าบริการ"
        Else
            panelGridItem.Visible = True
            lbAlert.Visible = False
            gridItem.DataSource = ViewState("Payment")
            gridItem.DataBind()
        End If

    End Sub

    Public Sub Paginate(ByVal sender As Object, ByVal e As CommandEventArgs)
        Dim CurrentIndex As Integer = gridItem.PageIndex
        Select Case e.CommandArgument.ToString().ToLower()
            Case "first"
                gridItem.PageIndex = 0
            Case "prev"
                If (gridItem.PageIndex <> 0) Then
                    gridItem.PageIndex = CurrentIndex - 1
                End If
            Case "next"
                If (gridItem.PageIndex <> gridItem.PageCount) Then
                    gridItem.PageIndex = CurrentIndex + 1
                End If
            Case "last"
                gridItem.PageIndex = gridItem.PageCount
        End Select
        gridItem.DataSource = ViewState("Payment")
        gridItem.DataBind()
    End Sub

    Protected Sub ddlPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim Page As GridViewRow = gridItem.BottomPagerRow
        Dim ddlPage As DropDownList = CType(Page.Cells(0).FindControl("ddlPage"), DropDownList)
        gridItem.PageIndex = ddlPage.SelectedIndex
        gridItem.DataSource = ViewState("Payment")
        gridItem.DataBind()
    End Sub


    Private Sub gridItem_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridItem.RowCommand
        Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
        If (gridItem.PageIndex <> 0) Then
            Index = Index Mod (gridItem.PageIndex * 10)
        End If
        If e.CommandName = "Edit" Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_contentplaceholder1_iframePayin').src = '../FormPopup/E-Pay.aspx';", True)
            Session("PayinBooking") = gridItem.DataKeys(Index).Values("Booking_no") & ""
            ModalPopupExtender7.Show()
        End If
    End Sub

    Private Sub gridItem_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridItem.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim imgVPS As Image = CType(e.Row.FindControl("imgVPS"), Image)
            Dim imgMRI As Image = CType(e.Row.FindControl("imgMRI"), Image)
            Dim imgMKT As Image = CType(e.Row.FindControl("imgMKT"), Image)
            Dim imgProduct As Image = CType(e.Row.FindControl("imgProduct"), Image)
            Dim imgCustom As Image = CType(e.Row.FindControl("imgCustom"), Image)
            Dim imgFinance As Image = CType(e.Row.FindControl("imgFinance"), Image)
            clsFc.GetImageStatus(imgVPS, imgMRI, imgMKT, gridItem.DataKeys(e.Row.RowIndex).Values("VPS_approve"), gridItem.DataKeys(e.Row.RowIndex).Values("MRI_approve"), gridItem.DataKeys(e.Row.RowIndex).Values("Marketing_approve"), gridItem.DataKeys(e.Row.RowIndex).Values("Status"))
            clsFc.GetImageStatusMKT(imgProduct, imgCustom, imgFinance, gridItem.DataKeys(e.Row.RowIndex).Values("MKT_Product"), gridItem.DataKeys(e.Row.RowIndex).Values("MKT_Custom"), gridItem.DataKeys(e.Row.RowIndex).Values("MKT_Finance"))
            If (gridItem.DataKeys(e.Row.RowIndex).Values("Date_From") & "" <> "") Then
                e.Row.Cells(2).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Date_From").ToString.Substring(0, 2) & "-" & gridItem.DataKeys(e.Row.RowIndex).Values("Date_To")
                e.Row.Cells(3).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Booking_Date") & " : " & gridItem.DataKeys(e.Row.RowIndex).Values("Booking_Time")
                e.Row.Cells(4).Text = e.Row.Cells(3).Text & " hours"
                e.Row.Cells(16).Text = ""   'ค่าปรับ
                If (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_Destination") & "" = "O") Then
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_TypeBuy") & "" = "F") Then
                        e.Row.Cells(17).Text = "FOB" 'รูปแบบการซื้อขาย
                    ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_TypeBuy") & "" = "C") Then
                        e.Row.Cells(17).Text = "CFR"
                    ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_TypeBuy") & "" = "I") Then
                        e.Row.Cells(17).Text = "CIF"
                    Else
                        e.Row.Cells(17).Text = "อื่นๆ" 'รูปแบบการซื้อขาย
                    End If
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage_Money") & "" = "B") Then
                        If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & "" = "") Then
                            e.Row.Cells(16).Text = "- BAHT"
                        Else
                            e.Row.Cells(16).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & " BAHT "
                        End If
                    ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage_Money") & "" = "U") Then
                        If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & "" = "") Then
                            e.Row.Cells(16).Text = "- USD"
                        Else
                            e.Row.Cells(16).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & " USD "
                        End If
                    Else
                        If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & "" = "") Then
                            e.Row.Cells(16).Text = "- PDPR"
                        Else
                            e.Row.Cells(16).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & " PDPR "
                        End If
                    End If
                Else
                    e.Row.Cells(17).Text = "" 'รูปแบบการซื้อขาย
                    e.Row.Cells(16).Text = ""
                End If
            End If
            If (clsFc.GetStatusCancel(gridItem.DataKeys(e.Row.RowIndex).Values("Status"))) Then
                e.Row.BackColor = Drawing.Color.Red
            End If
        ElseIf (e.Row.RowType = DataControlRowType.Pager) Then
            Dim Page As GridViewRow = gridItem.BottomPagerRow
            Dim ddlPage As DropDownList = CType(e.Row.FindControl("ddlPage"), DropDownList)
            Dim lblPageCount As Label = CType(e.Row.FindControl("lbPageCount"), Label)
            If Not (ddlPage Is Nothing) Then
                For i As Integer = 0 To gridItem.PageCount - 1
                    Dim intPageNumber As Integer = i + 1
                    Dim IsItem As New ListItem(intPageNumber.ToString())
                    If (i = gridItem.PageIndex) Then
                        IsItem.Selected = True
                    End If
                    ddlPage.Items.Add(IsItem)
                Next
            End If
            If Not (lblPageCount Is Nothing) Then
                lblPageCount.Text = gridItem.PageCount.ToString()
            End If
        End If
    End Sub

    Private Sub gridItem_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridItem.RowCreated
        If e.Row.RowType = DataControlRowType.Header Then
            Dim Grid As GridView = CType(sender, GridView)
            e.Row.Cells.Clear()
            Dim GridRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
            Dim GridRow1 As GridViewRow = New GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert)

            Dim table As TableCell = New TableCell()
            table.Text = ""
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "BOOKING NO."
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "LAY CAN/LAY DAY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "วัน/เวลาจองเข้า"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "LAY TIME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "VESSEL NAME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "เอกสารรายละเอียด"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "COMMODITY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "QUANTITY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "UNIT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "BUYER"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)


            table = New TableCell()
            table.Text = "SELLER"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "APPROVE BY MKT"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.ColumnSpan = 5
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "APPROVE BY"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.ColumnSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "ค่าประมาณการ"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "AGENT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "WHARF"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "PLAN BERTH DATE"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "PLAN BERTH TIME"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "PLAN DEPART DATE"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "PLAN DEPART TIME"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "REMAIN LAYTIME(ESTIMATE)"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "REMARK"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.RowSpan = 2
            'table.Wrap = True
            'GridRow1.Cells.Add(table)

            Grid.Controls(0).Controls.AddAt(0, GridRow1)

            'table = New TableCell()
            'table.Text = "PRODUCT"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "CUSTOM"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "FINANCE"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "DEMURRAGE"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "TERM"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "PTMP"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            'table = New TableCell()
            'table.Text = "PTMI"
            'table.HorizontalAlign = HorizontalAlign.Center
            'table.Wrap = True
            'GridRow.Cells.Add(table)

            Grid.Controls(0).Controls.AddAt(1, GridRow)
        End If
    End Sub

    Private Sub gridItem_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gridItem.RowEditing

    End Sub

    Private Sub TabPayment_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPayment.ActiveTabChanged
        If (TabPayment.ActiveTabIndex = 0) Then
            LoadPayment()
        ElseIf (TabPayment.ActiveTabIndex = 1) Then
            LoadCNDN()
        ElseIf (TabPayment.ActiveTabIndex = 2) Then
            LoadPaymentRecord()
        End If
    End Sub

    Private Sub LoadCNDN()
        btnPayDS.Visible = False
        btnPayOX.Visible = False
        Dim ClassSAP As New Class_SAP
        Dim SAP_Data As Object = ClassSAP.SAP_OPEN()

        Dim CompanyCode As String = "1001"
        Dim CustomerCode As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Customer_no")
        Dim EX_SUBRC As String = "0"  'ถ้ามีค่าเป็น 0 คือพบข้อมูล
        Dim BABI_ARTABLE As New SAP_IPORT.ZBAPI_AR_OPENTable
        SAP_Data.Zbapi_Iport_Ar_Open_Item(CompanyCode, CustomerCode, EX_SUBRC, BABI_ARTABLE)
        Dim dt As DataTable = CreateTable()
        Dim dtDeferred As DataTable = CreateTable()
        If (EX_SUBRC = "0") Then
            For Each S As SAP_IPORT.ZBAPI_AR_OPEN In BABI_ARTABLE
                ' dt = addValue(dt, S)
                If (S.Blart = "R1") Or (S.Blart = "R5") Or (S.Blart = "R7") Then
                    If (S.Mwskz <> "") Then
                        If (S.Mwskz = "DS") Then
                            dtDeferred = addValue(dtDeferred, S)
                        Else
                            dt = addValue(dt, S)
                        End If
                    End If
                End If

            Next
        End If
        If (dt.Rows.Count = 0) Then
            lbAlertVat.Visible = True
            lbAlertVat.Text = "ไม่พบรายการ CN,DN"
        Else
            lbAlertVat.Visible = False
        End If
        If (dtDeferred.Rows.Count = 0) Then
            lbAlertDeferred.Visible = True
            lbAlertDeferred.Text = "ไม่พบรายการ CN,DN"
        Else
            lbAlertDeferred.Visible = False
        End If
        gridCNDN.DataSource = SetDate(dt)
        gridCNDN.DataBind()
        gridDefferred.DataSource = SetDate(dtDeferred)
        gridDefferred.DataBind()
        ClassSAP.SAP_CLOSE(SAP_Data)
    End Sub

    Public Sub chkCNDN_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim BASE As Double = 0
        Dim VAT As Double = 0
        Dim NET As Double = 0
        Dim WHT As Double = 0
        For i As Integer = 0 To gridCNDN.Rows.Count - 1
            Dim chk As CheckBox = CType(gridCNDN.Rows(i).FindControl("chkCNDN"), CheckBox)
            If (chk.Checked) Then
                Try
                    BASE += CDbl(gridCNDN.Rows(i).Cells(7).Text)
                    VAT += CDbl(gridCNDN.Rows(i).Cells(8).Text)
                    NET += CDbl(gridCNDN.Rows(i).Cells(9).Text)
                    WHT += CDbl(gridCNDN.Rows(i).Cells(10).Text)
                Catch ex As Exception

                End Try
            End If
        Next
        gridCNDN.FooterRow.Cells(7).Text = FormatNumber(BASE, 2)
        gridCNDN.FooterRow.Cells(8).Text = FormatNumber(VAT, 2)
        gridCNDN.FooterRow.Cells(9).Text = FormatNumber(NET, 2)
        gridCNDN.FooterRow.Cells(10).Text = FormatNumber(WHT, 2)
        lbMoneyCNDN.Text = FormatNumber(NET - WHT, 2) & " บาท"
    End Sub

    Public Sub chkDefferred_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim BASE As Double = 0
        Dim VAT As Double = 0
        Dim NET As Double = 0
        Dim WHT As Double = 0
        For i As Integer = 0 To gridDefferred.Rows.Count - 1
            Dim chk As CheckBox = CType(gridDefferred.Rows(i).FindControl("chkCNDN"), CheckBox)
            If (chk.Checked) Then
                Try
                    BASE += CDbl(gridDefferred.Rows(i).Cells(7).Text)
                    VAT += CDbl(gridDefferred.Rows(i).Cells(8).Text)
                    NET += CDbl(gridDefferred.Rows(i).Cells(9).Text)
                    WHT += CDbl(gridDefferred.Rows(i).Cells(10).Text)
                Catch ex As Exception

                End Try
            End If
        Next
        gridDefferred.FooterRow.Cells(7).Text = FormatNumber(BASE, 2)
        gridDefferred.FooterRow.Cells(8).Text = FormatNumber(VAT, 2)
        gridDefferred.FooterRow.Cells(9).Text = FormatNumber(NET, 2)
        gridDefferred.FooterRow.Cells(10).Text = FormatNumber(WHT, 2)
        lbMoneyDeferred.Text = FormatNumber(NET - WHT, 2) & " บาท"
    End Sub

    Public Function SetDate(ByVal dt As DataTable) As DataTable
        Dim Newdt As DataTable = CreateTable()
        Newdt.Columns.Add("Ship_Name", GetType(String))
        Newdt.Columns.Add("Booking_no", GetType(String))
        Newdt.AcceptChanges()
        For Each dr As DataRow In dt.Rows
            Dim dtBiiling As DataTable = clsGet.Get_VesselFrom_Billing(dr.Item("ALLOC_NMBR"))
            If (dtBiiling.Rows.Count = 1) Then
                Dim drNew As DataRow = Newdt.NewRow
                drNew.Item("BUKRS") = dr.Item("BUKRS")
                drNew.Item("BELNR") = dr.Item("BELNR")
                drNew.Item("GJAHR") = dr.Item("GJAHR")
                drNew.Item("BUZEI") = dr.Item("BUZEI")
                drNew.Item("BILL_TO") = dr.Item("BILL_TO")
                drNew.Item("MWSKZ") = dr.Item("MWSKZ")
                drNew.Item("BLART") = dr.Item("BLART")
                drNew.Item("DOC_DESC") = dr.Item("DOC_DESC")
                drNew.Item("XBLNR") = dr.Item("XBLNR")
                drNew.Item("ALLOC_NMBR") = dr.Item("ALLOC_NMBR")
                drNew.Item("BLDAT") = dr.Item("BLDAT")
                drNew.Item("DUEDT") = dr.Item("DUEDT")
                drNew.Item("WAERS") = dr.Item("WAERS")
                drNew.Item("BASMAT") = dr.Item("BASMAT")
                drNew.Item("VAT") = dr.Item("VAT")
                drNew.Item("NETAMT") = dr.Item("NETAMT")
                drNew.Item("WHTAMT") = dr.Item("WHTAMT")
                drNew.Item("TEXT40") = dr.Item("TEXT40")
                drNew.Item("REBZG") = dr.Item("REBZG")
                drNew.Item("REBZJ") = dr.Item("REBZJ")
                drNew.Item("REBZZ") = dr.Item("REBZZ")
                drNew.Item("Ship_Name") = dtBiiling.Rows(0).Item("Ship_Name") & ""
                drNew.Item("Booking_no") = dtBiiling.Rows(0).Item("Booking_no") & ""
                Newdt.Rows.Add(drNew)
                Newdt.AcceptChanges()
            End If
        Next

        Dim dsView As DataView = Newdt.DefaultView
        dsView.Sort = " Booking_no"
        Newdt = New DataTable
        Newdt = (clsGet.ConvertDataViewToDataSet(dsView).Copy)

        Dim Booking_no As String = ""
        Dim dataCNDN As DataTable = Newdt.Clone
        dataCNDN.Columns.Add("TYPE_DOC", GetType(String))
        dataCNDN.AcceptChanges()
        Dim BASE As Double = 0
        Dim VAT As Double = 0
        Dim NET As Double = 0
        Dim WHT As Double = 0
        Dim chkFirst As Boolean = True
        For i As Integer = 0 To Newdt.Rows.Count - 1
            Dim drNew As DataRow
            If (Newdt.Rows(i).Item("Booking_no") <> Booking_no) Then
                If Not (chkFirst) Then
                    drNew = dataCNDN.NewRow
                    drNew.Item("TYPE_DOC") = "Total(By Ship)"
                    drNew.Item("BUKRS") = ""
                    drNew.Item("BELNR") = ""
                    drNew.Item("GJAHR") = ""
                    drNew.Item("BUZEI") = ""
                    drNew.Item("BILL_TO") = ""
                    drNew.Item("MWSKZ") = ""
                    drNew.Item("BLART") = ""
                    drNew.Item("DOC_DESC") = ""
                    drNew.Item("XBLNR") = ""
                    drNew.Item("ALLOC_NMBR") = ""
                    drNew.Item("BLDAT") = ""
                    drNew.Item("DUEDT") = ""
                    drNew.Item("WAERS") = ""
                    drNew.Item("BASMAT") = FormatNumber(BASE, 2)
                    drNew.Item("VAT") = FormatNumber(VAT, 2)
                    drNew.Item("NETAMT") = FormatNumber(NET, 2)
                    drNew.Item("WHTAMT") = FormatNumber(WHT, 2)
                    drNew.Item("TEXT40") = ""
                    drNew.Item("REBZG") = ""
                    drNew.Item("REBZJ") = ""
                    drNew.Item("REBZZ") = ""
                    drNew.Item("Ship_Name") = "_F"
                    drNew.Item("Booking_no") = Newdt.Rows(i).Item("Booking_no") & ""
                    dataCNDN.Rows.Add(drNew)
                    dataCNDN.AcceptChanges()

                    drNew = dataCNDN.NewRow
                    drNew.Item("TYPE_DOC") = ""
                    drNew.Item("BUKRS") = ""
                    drNew.Item("BELNR") = ""
                    drNew.Item("GJAHR") = ""
                    drNew.Item("BUZEI") = ""
                    drNew.Item("BILL_TO") = ""
                    drNew.Item("MWSKZ") = ""
                    drNew.Item("BLART") = ""
                    drNew.Item("DOC_DESC") = ""
                    drNew.Item("XBLNR") = ""
                    drNew.Item("ALLOC_NMBR") = ""
                    drNew.Item("BLDAT") = ""
                    drNew.Item("DUEDT") = ""
                    drNew.Item("WAERS") = ""
                    drNew.Item("BASMAT") = ""
                    drNew.Item("VAT") = ""
                    drNew.Item("NETAMT") = ""
                    drNew.Item("WHTAMT") = ""
                    drNew.Item("TEXT40") = ""
                    drNew.Item("REBZG") = ""
                    drNew.Item("REBZJ") = ""
                    drNew.Item("REBZZ") = ""
                    drNew.Item("Ship_Name") = ""
                    drNew.Item("Booking_no") = ""
                    dataCNDN.Rows.Add(drNew)
                    dataCNDN.AcceptChanges()
                Else
                    chkFirst = False
                End If
                Booking_no = Newdt.Rows(i).Item("Booking_no")
                drNew = dataCNDN.NewRow
                drNew.Item("TYPE_DOC") = "เรือ : " & Newdt.Rows(i).Item("Ship_Name") & ""
                drNew.Item("BUKRS") = ""
                drNew.Item("BELNR") = ""
                drNew.Item("GJAHR") = ""
                drNew.Item("BUZEI") = ""
                drNew.Item("BILL_TO") = ""
                drNew.Item("MWSKZ") = ""
                drNew.Item("BLART") = ""
                drNew.Item("DOC_DESC") = ""
                drNew.Item("XBLNR") = ""
                drNew.Item("ALLOC_NMBR") = "Booking No. : " & Newdt.Rows(i).Item("Booking_no") & ""
                drNew.Item("BLDAT") = ""
                drNew.Item("DUEDT") = ""
                drNew.Item("WAERS") = ""
                drNew.Item("BASMAT") = ""
                drNew.Item("VAT") = ""
                drNew.Item("NETAMT") = ""
                drNew.Item("WHTAMT") = ""
                drNew.Item("TEXT40") = ""
                drNew.Item("REBZG") = ""
                drNew.Item("REBZJ") = ""
                drNew.Item("REBZZ") = ""
                drNew.Item("Ship_Name") = "_H"
                drNew.Item("Booking_no") = Newdt.Rows(i).Item("Booking_no") & ""
                dataCNDN.Rows.Add(drNew)
                dataCNDN.AcceptChanges()
            End If
            drNew = dataCNDN.NewRow
            drNew.Item("TYPE_DOC") = Newdt.Rows(i).Item("BLART") & " : " & Newdt.Rows(i).Item("DOC_DESC")
            drNew.Item("BUKRS") = Newdt.Rows(i).Item("BUKRS")
            drNew.Item("BELNR") = Newdt.Rows(i).Item("BELNR")
            drNew.Item("GJAHR") = Newdt.Rows(i).Item("GJAHR")
            drNew.Item("BUZEI") = Newdt.Rows(i).Item("BUZEI")
            drNew.Item("BILL_TO") = Newdt.Rows(i).Item("BILL_TO")
            drNew.Item("MWSKZ") = Newdt.Rows(i).Item("MWSKZ")
            drNew.Item("BLART") = Newdt.Rows(i).Item("BLART")
            drNew.Item("DOC_DESC") = Newdt.Rows(i).Item("DOC_DESC")
            drNew.Item("XBLNR") = Newdt.Rows(i).Item("XBLNR")
            drNew.Item("ALLOC_NMBR") = Newdt.Rows(i).Item("ALLOC_NMBR")
            drNew.Item("BLDAT") = Newdt.Rows(i).Item("BLDAT")
            drNew.Item("DUEDT") = Newdt.Rows(i).Item("DUEDT")
            drNew.Item("WAERS") = Newdt.Rows(i).Item("WAERS")
            drNew.Item("BASMAT") = Newdt.Rows(i).Item("BASMAT")
            drNew.Item("VAT") = Newdt.Rows(i).Item("VAT")
            drNew.Item("NETAMT") = Newdt.Rows(i).Item("NETAMT")
            drNew.Item("WHTAMT") = Newdt.Rows(i).Item("WHTAMT")
            drNew.Item("TEXT40") = Newdt.Rows(i).Item("TEXT40")
            drNew.Item("REBZG") = Newdt.Rows(i).Item("REBZG")
            drNew.Item("REBZJ") = Newdt.Rows(i).Item("REBZJ")
            drNew.Item("REBZZ") = Newdt.Rows(i).Item("REBZZ")
            drNew.Item("Ship_Name") = Newdt.Rows(i).Item("Ship_Name") & ""
            drNew.Item("Booking_no") = Newdt.Rows(i).Item("Booking_no") & ""
            Try
                BASE += CDbl(Newdt.Rows(i).Item("BASMAT"))
                VAT += CDbl(Newdt.Rows(i).Item("VAT"))
                NET += CDbl(Newdt.Rows(i).Item("NETAMT"))
                WHT += CDbl(Newdt.Rows(i).Item("WHTAMT"))
            Catch ex As Exception

            End Try
            dataCNDN.Rows.Add(drNew)
            dataCNDN.AcceptChanges()
        Next
        If (Newdt.Rows.Count > 0) Then
            Dim drNew As DataRow = dataCNDN.NewRow
            drNew.Item("TYPE_DOC") = "Total(By Ship)"
            drNew.Item("BUKRS") = ""
            drNew.Item("BELNR") = ""
            drNew.Item("GJAHR") = ""
            drNew.Item("BUZEI") = ""
            drNew.Item("BILL_TO") = ""
            drNew.Item("MWSKZ") = ""
            drNew.Item("BLART") = ""
            drNew.Item("DOC_DESC") = ""
            drNew.Item("XBLNR") = ""
            drNew.Item("ALLOC_NMBR") = ""
            drNew.Item("BLDAT") = ""
            drNew.Item("DUEDT") = ""
            drNew.Item("WAERS") = ""
            drNew.Item("BASMAT") = FormatNumber(BASE, 2)
            drNew.Item("VAT") = FormatNumber(VAT, 2)
            drNew.Item("NETAMT") = FormatNumber(NET, 2)
            drNew.Item("WHTAMT") = FormatNumber(WHT, 2)
            drNew.Item("TEXT40") = ""
            drNew.Item("REBZG") = ""
            drNew.Item("REBZJ") = ""
            drNew.Item("REBZZ") = ""
            drNew.Item("Ship_Name") = "_F"
            drNew.Item("Booking_no") = ""
            dataCNDN.Rows.Add(drNew)
            dataCNDN.AcceptChanges()

            drNew = dataCNDN.NewRow
            drNew.Item("TYPE_DOC") = ""
            drNew.Item("BUKRS") = ""
            drNew.Item("BELNR") = ""
            drNew.Item("GJAHR") = ""
            drNew.Item("BUZEI") = ""
            drNew.Item("BILL_TO") = ""
            drNew.Item("MWSKZ") = ""
            drNew.Item("BLART") = ""
            drNew.Item("DOC_DESC") = ""
            drNew.Item("XBLNR") = ""
            drNew.Item("ALLOC_NMBR") = ""
            drNew.Item("BLDAT") = ""
            drNew.Item("DUEDT") = ""
            drNew.Item("WAERS") = ""
            drNew.Item("BASMAT") = ""
            drNew.Item("VAT") = ""
            drNew.Item("NETAMT") = ""
            drNew.Item("WHTAMT") = ""
            drNew.Item("TEXT40") = ""
            drNew.Item("REBZG") = ""
            drNew.Item("REBZJ") = ""
            drNew.Item("REBZZ") = ""
            drNew.Item("Ship_Name") = ""
            drNew.Item("Booking_no") = ""
            dataCNDN.Rows.Add(drNew)
            dataCNDN.AcceptChanges()
        End If
        Return dataCNDN
    End Function

    Private Function CreateTable() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("BUKRS", GetType(String))  'Company Code
        dt.Columns.Add("BELNR", GetType(String))   'Accounting Document Number
        dt.Columns.Add("GJAHR", GetType(String))   'Fiscal Year
        dt.Columns.Add("BUZEI", GetType(String))   'Number of Line Item Within Accounting Document
        dt.Columns.Add("BILL_TO", GetType(String))   'Customer Number 1
        dt.Columns.Add("MWSKZ", GetType(String))    'Sales Tax Code
        dt.Columns.Add("BLART", GetType(String))    'Document Type
        dt.Columns.Add("DOC_DESC", GetType(String))   'Long Text
        dt.Columns.Add("XBLNR", GetType(String))   'Reference Document Number
        dt.Columns.Add("ALLOC_NMBR", GetType(String))   'Assignment Number
        dt.Columns.Add("BLDAT", GetType(String))   'Document Date in Document
        dt.Columns.Add("DUEDT", GetType(String))   'Due date
        dt.Columns.Add("WAERS", GetType(String))   'Currency Key
        dt.Columns.Add("BASMAT", GetType(String))  'Amount in Local Currency
        dt.Columns.Add("VAT", GetType(String))    'Tax Amount in Local Currency
        dt.Columns.Add("NETAMT", GetType(String))  'Amount in Local Currency
        dt.Columns.Add("WHTAMT", GetType(String))   'Withholding tax amount (in local currency)
        dt.Columns.Add("TEXT40", GetType(String))   'Text, 40 Characters Long
        dt.Columns.Add("REBZG", GetType(String))   'Number of the Invoice the Transaction Belongs to
        dt.Columns.Add("REBZJ", GetType(String))   'Fiscal Year of the Relevant Invoice (for Credit Memo)
        dt.Columns.Add("REBZZ", GetType(String))   'Line Item in the Relevant Invoice
        dt.AcceptChanges()
        Return dt
    End Function

    Private Function addValue(ByVal dt As DataTable, ByVal S As SAP_IPORT.ZBAPI_AR_OPEN) As DataTable
        Dim dr As DataRow = dt.NewRow
        dr.Item("BUKRS") = S.Bukrs  'Company Code
        dr.Item("BELNR") = S.Belnr  'Accounting Document Number
        dr.Item("GJAHR") = S.Gjahr 'Fiscal Year
        dr.Item("BUZEI") = S.Buzei   'Number of Line Item Within Accounting Document
        dr.Item("BILL_TO") = S.Bill_To  'Customer Number 1
        dr.Item("MWSKZ") = S.Mwskz    'Sales Tax Code
        dr.Item("BLART") = S.Blart   'Document Type
        dr.Item("DOC_DESC") = S.Doc_Desc   'Long Text
        dr.Item("XBLNR") = S.Xblnr  'Reference Document Number
        dr.Item("ALLOC_NMBR") = S.Alloc_Nmbr  'Assignment Number
        dr.Item("BLDAT") = S.Bldat   'Document Date in Document
        dr.Item("DUEDT") = S.Duedt   'Due date
        dr.Item("WAERS") = S.Waers  'Currency Key
        dr.Item("BASMAT") = S.Basmat  'Amount in Local Currency
        dr.Item("VAT") = S.Vat    'Tax Amount in Local Currency
        dr.Item("NETAMT") = S.Netamt 'Amount in Local Currency
        dr.Item("WHTAMT") = S.Whtamt  'Withholding tax amount (in local currency)
        dr.Item("TEXT40") = S.Text40   'Text, 40 Characters Long
        dr.Item("REBZG") = S.Rebzg  'Number of the Invoice the Transaction Belongs to
        dr.Item("REBZJ") = S.Rebzj   'Fiscal Year of the Relevant Invoice (for Credit Memo)
        dr.Item("REBZZ") = S.Rebzz  'Line Item in the Relevant Invoice
        dt.Rows.Add(dr)
        dt.AcceptChanges()
        Return dt
    End Function

    Private Sub btnPayOX_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPayOX.Click
        If (ddlBankOX.SelectedValue = "0") Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการเลือกธนาคารที่ต้องการทำการชำระเงิน ');", True)
            Exit Sub
        ElseIf (ddlBankOX.SelectedValue = "") Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ธนาคารที่เลือกยังไม่เปิดให้ใช้บริการ ');", True)
            Exit Sub
        End If
        ViewState("EX_BELNR") = ""
        Dim dt As DataTable = dt_Clearing()
        ViewState("ALLOC_NMBR") = ""
        Dim First As Boolean = True
        Dim Ship_Name As String = ""
        Dim Booking_no As String = ""
        Dim Conditon As Boolean = True
        Dim CountText As String = ""
        Dim Count As Integer = 0
        For i As Integer = 0 To gridCNDN.Rows.Count - 1
            Dim chkCNDN As CheckBox = CType(gridCNDN.Rows(i).FindControl("chkCNDN"), CheckBox)
            If chkCNDN.Checked Then
                Dim ch As Boolean = True
                For k As Integer = 0 To CountText.Split(",").Count - 1
                    If (gridCNDN.DataKeys(i).Values("BILL_TO") = CountText.Split(",")(k)) Then
                        ch = False
                        Exit For
                    End If
                Next
                If (ch) Then
                    Count += 1
                    If (CountText = "") Then
                        CountText = gridCNDN.DataKeys(i).Values("BILL_TO")
                    Else
                        CountText &= "," & gridCNDN.DataKeys(i).Values("BILL_TO")
                    End If

                End If
            End If
        Next
        For L As Integer = 0 To Count - 1
            dt = dt_Clearing()
            For i As Integer = 0 To gridCNDN.Rows.Count - 1
                Dim chkCNDN As CheckBox = CType(gridCNDN.Rows(i).FindControl("chkCNDN"), CheckBox)
                If chkCNDN.Checked Then
                    Ship_Name = ""
                    Booking_no = gridCNDN.DataKeys(i).Values("Booking_no")
                    ViewState("ALLOC_NMBR") = gridCNDN.DataKeys(i).Values("ALLOC_NMBR")
                    Dim dr As DataRow = dt.NewRow

                    dr.Item("Bukrs") = gridCNDN.DataKeys(i).Values("BUKRS")
                    dr.Item("Gjahr") = gridCNDN.DataKeys(i).Values("GJAHR")
                    dr.Item("Belnr") = gridCNDN.DataKeys(i).Values("BELNR")
                    dr.Item("Blart") = gridCNDN.DataKeys(i).Values("BLART")
                    dr.Item("Waers") = gridCNDN.DataKeys(i).Values("WAERS")
                    dr.Item("Whtamt") = gridCNDN.DataKeys(i).Values("WHTAMT")
                    dr.Item("Netamt") = gridCNDN.DataKeys(i).Values("NETAMT")
                    dt.Rows.Add(dr)
                    dt.AcceptChanges()
                End If
            Next
            Conditon = inCOMEpayment(dt, Ship_Name, ddlBankOX.SelectedValue, Booking_no)
            If Not (Conditon) Then
                Exit For
            End If
        Next

        If (Conditon) Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ชำระเงินเรียบร้อย ');", True)
        Else
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('เกิดความผิดพลาดในการชำระเงิน ');", True)
        End If
        '************************
        'Dim chkInvoice As Boolean = False
        'Dim dt As DataTable = dt_Clearing()
        'Dim dtBooking As New DataTable
        'For i As Integer = 0 To gridCNDN.Rows.Count - 1
        '    Dim chkCNDN As CheckBox = CType(gridCNDN.Rows(i).FindControl("chkCNDN"), CheckBox)
        '    If (chkCNDN.Checked) Then
        '        If (gridCNDN.DataKeys(i).Values("BLART") & "" = "R1") Then
        '            If Not (chkInvoice) Then
        '                chkInvoice = True
        '                dtBooking = clsGet.GetVehicle_TextByBilling(gridCNDN.DataKeys(i).Values("ALLOC_NMBR"))
        '                ViewState("ALLOC_NMBR") = gridCNDN.DataKeys(i).Values("ALLOC_NMBR")
        '            Else
        '                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการเลือก Invoice ที่ต้องทำการชำระเพีบง 1 รายการเท่านั้น ');", True)
        '            End If
        '        End If
        '        Dim dr As DataRow = dt.NewRow
        '        dr.Item("Bukrs") = gridCNDN.DataKeys(i).Values("BUKRS")
        '        dr.Item("Gjahr") = gridCNDN.DataKeys(i).Values("GJAHR")
        '        dr.Item("Belnr") = gridCNDN.DataKeys(i).Values("BELNR")
        '        dr.Item("Blart") = gridCNDN.DataKeys(i).Values("BLART")
        '        dr.Item("Waers") = gridCNDN.DataKeys(i).Values("WAERS")
        '        dr.Item("Whtamt") = gridCNDN.DataKeys(i).Values("WHTAMT")
        '        dr.Item("Netamt") = gridCNDN.DataKeys(i).Values("NETAMT")
        '        dt.Rows.Add(dr)
        '        dt.AcceptChanges()
        '    End If
        'Next
        'chkInvoice = True
        'If (chkInvoice) Then
        '    inCOMEpayment(dt, dtBooking.Rows(0).Item("Vehicle_Text"), ddlBankOX.SelectedValue, dtBooking.Rows(0).Item("Booking_no"))
        '    LoadCNDN()
        'Else
        '    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการเลือก Invoice ที่ต้องทำการชำระ ');", True)
        'End If
    End Sub

    Private Sub btnPayDS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPayDS.Click
        If (ddlBankDS.SelectedValue = "0") Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการเลือกธนาคารที่ต้องการทำการชำระเงิน ');", True)
            Exit Sub
        ElseIf (ddlBankDS.SelectedValue = "") Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ธนาคารที่เลือกยังไม่เปิดให้ใช้บริการ ');", True)
            Exit Sub
        End If
        Dim dt As DataTable = dt_Clearing()
        ViewState("ALLOC_NMBR") = ""
        Dim First As Boolean = True
        Dim Ship_Name As String = ""
        Dim Booking_no As String = ""
        Dim Conditon As Boolean = True
        Dim CountText As String = ""
        Dim Count As Integer = 0
        For i As Integer = 0 To gridDefferred.Rows.Count - 1
            Dim chkCNDN As CheckBox = CType(gridDefferred.Rows(i).FindControl("chkCNDN"), CheckBox)
            If chkCNDN.Checked Then
                Dim ch As Boolean = True
                For k As Integer = 0 To CountText.Split(",").Count - 1
                    If (gridDefferred.DataKeys(i).Values("BILL_TO") = CountText.Split(",")(k)) Then
                        ch = False
                        Exit For
                    End If
                Next
                If (ch) Then
                    Count += 1
                    If (CountText = "") Then
                        CountText = gridDefferred.DataKeys(i).Values("BILL_TO")
                    Else
                        CountText &= "," & gridDefferred.DataKeys(i).Values("BILL_TO")
                    End If

                End If
            End If
        Next
        For L As Integer = 0 To Count - 1
            dt = dt_Clearing()
            For i As Integer = 0 To gridDefferred.Rows.Count - 1
                Dim chkCNDN As CheckBox = CType(gridDefferred.Rows(i).FindControl("chkCNDN"), CheckBox)
                If chkCNDN.Checked Then
                    Ship_Name = ""
                    Booking_no = gridDefferred.DataKeys(i).Values("Booking_no")
                    ViewState("ALLOC_NMBR") = gridDefferred.DataKeys(i).Values("ALLOC_NMBR")
                    Dim dr As DataRow = dt.NewRow

                    dr.Item("Bukrs") = gridDefferred.DataKeys(i).Values("BUKRS")
                    dr.Item("Gjahr") = gridDefferred.DataKeys(i).Values("GJAHR")
                    dr.Item("Belnr") = gridDefferred.DataKeys(i).Values("BELNR")
                    dr.Item("Blart") = gridDefferred.DataKeys(i).Values("BLART")
                    dr.Item("Waers") = gridDefferred.DataKeys(i).Values("WAERS")
                    dr.Item("Whtamt") = gridDefferred.DataKeys(i).Values("WHTAMT")
                    dr.Item("Netamt") = gridDefferred.DataKeys(i).Values("NETAMT")
                    dt.Rows.Add(dr)
                    dt.AcceptChanges()
                End If
            Next
            Conditon = inCOMEpayment(dt, Ship_Name, ddlBankDS.SelectedValue, Booking_no)
            If Not (Conditon) Then
                Exit For
            End If
        Next

        If (Conditon) Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ชำระเงินเรียบร้อย ');", True)
        Else
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('เกิดความผิดพลาดในการชำระเงิน ');", True)
        End If
        '*************************
        'Dim chkInvoice As Boolean = False
        'Dim dt As DataTable = dt_Clearing()
        'Dim dtBooking As New DataTable
        'For i As Integer = 0 To gridDefferred.Rows.Count - 1
        '    Dim chkCNDN As CheckBox = CType(gridDefferred.Rows(i).FindControl("chkCNDN"), CheckBox)
        '    If (chkCNDN.Checked) Then
        '        If (gridDefferred.DataKeys(i).Values("BLART") & "" = "R1") Then
        '            If Not (chkInvoice) Then
        '                chkInvoice = True
        '                dtBooking = clsGet.GetVehicle_TextByBilling(gridDefferred.DataKeys(i).Values("XBLNR"))
        '                ViewState("ALLOC_NMBR") = gridDefferred.DataKeys(i).Values("XBLNR")
        '            Else
        '                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการเลือก Invoice ที่ต้องทำการชำระเพีบง 1 รายการเท่านั้น ');", True)
        '            End If
        '        End If
        '        Dim dr As DataRow = dt.NewRow
        '        dr.Item("Bukrs") = gridDefferred.DataKeys(i).Values("BUKRS")
        '        dr.Item("Gjahr") = gridDefferred.DataKeys(i).Values("GJAHR")
        '        dr.Item("Belnr") = gridDefferred.DataKeys(i).Values("BELNR")
        '        dr.Item("Blart") = gridDefferred.DataKeys(i).Values("BLART")
        '        dr.Item("Waers") = gridDefferred.DataKeys(i).Values("WAERS")
        '        dr.Item("Whtamt") = gridDefferred.DataKeys(i).Values("WHTAMT")
        '        dr.Item("Netamt") = gridDefferred.DataKeys(i).Values("NETAMT")
        '        dt.Rows.Add(dr)
        '        dt.AcceptChanges()
        '    End If
        'Next
        'chkInvoice = True
        'If (chkInvoice) Then
        '    inCOMEpayment(dt, dtBooking.Rows(0).Item("Vehicle_Text"), ddlBankDS.SelectedValue, dtBooking.Rows(0).Item("Booking_no"))
        '    LoadCNDN()
        'Else
        '    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการเลือก Invoice ที่ต้องทำการชำระ ');", True)
        'End If
    End Sub

    Private Function dt_Clearing() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Bukrs", GetType(String))
        dt.Columns.Add("Gjahr", GetType(String))
        dt.Columns.Add("Belnr", GetType(String))
        dt.Columns.Add("Blart", GetType(String))
        dt.Columns.Add("Waers", GetType(String))
        dt.Columns.Add("Whtamt", GetType(String))
        dt.Columns.Add("Netamt", GetType(String))
        dt.AcceptChanges()
        Return dt
    End Function

    Private Function inCOMEpayment(ByVal dt As DataTable, ByVal Vessel_Name As String, ByVal Bank As String, ByVal Booking_no As String) As Boolean
        Dim ClassSAP As New Class_SAP
        Dim SAP_Data As Object = ClassSAP.SAP_OPEN()

        Dim BABI_CLEARING As SAP_IPORT.ZBAPI_CLEARING
        Dim BABI_CLEARINGTB As New SAP_IPORT.ZBAPI_CLEARINGTable
        Dim sumAmount As Double = 0
        Dim Wht As Double = 0
        For Each dr As DataRow In dt.Rows
            BABI_CLEARING = New SAP_IPORT.ZBAPI_CLEARING
            BABI_CLEARING.Comp_Code = dr.Item("Bukrs")
            BABI_CLEARING.Fisc_Year = dr.Item("Gjahr")
            BABI_CLEARING.Ac_Doc_No = dr.Item("Belnr")
            BABI_CLEARING.Blart = dr.Item("Blart")
            BABI_CLEARING.Waers = dr.Item("Waers")
            BABI_CLEARING.Whtamt = dr.Item("Whtamt")
            BABI_CLEARINGTB.Insert(0, BABI_CLEARING)
            sumAmount += CDbl(dr.Item("Netamt"))
            Wht += CDbl(dr.Item("Whtamt"))
        Next
        If (sumAmount >= 0.0) Then
            Dim EX_BUKRS As String = ""
            Dim EX_BELNR As String = ""
            Dim EX_GJAHR As String = ""
            Dim IPORT_NUMBER As String = clsGet.Get_IportNumber()
            Dim CustomerCode As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Customer_no")
            Dim ZBABI_BK As New SAP_IPORT.ZBAPI_BANK
            ZBABI_BK.Amount = sumAmount.ToString("##############.##")
            ZBABI_BK.Gl_Account = "0010302031"
            ZBABI_BK.Item_Text = "TR " & Bank
            ZBABI_BK.Value_Date = Date.Now.ToString("yyyyMMdd", New CultureInfo("en-US"))

            Dim ZBABI_HD As New SAP_IPORT.ZBAPI_HEADER
            ZBABI_HD.Bupla = "0000"
            ZBABI_HD.Doc_Date = Date.Now.ToString("yyyyMMdd", New CultureInfo("en-US"))
            ZBABI_HD.Header_Txt = "R|" & Vessel_Name
            ZBABI_HD.Pstng_Date = Date.Now.ToString("yyyyMMdd", New CultureInfo("en-US"))
            Dim BABITable As New SAP_IPORT.BAPIRET1Table

            SAP_Data.Zbapi_Iport_Income_Payment(ZBABI_BK, CustomerCode, ZBABI_HD, IPORT_NUMBER, "X", EX_BELNR, EX_BUKRS, EX_GJAHR, BABI_CLEARINGTB, BABITable)

            If (EX_BUKRS <> "") And (EX_BELNR <> "") And (EX_GJAHR <> "") Then
                Dim clsDB As New ClassDatabase()
                Dim clsFc As New ClassFunction()
                Dim conn As New System.Data.SqlClient.SqlConnection(connString)
                Dim condition As Boolean = True
                Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
                Application.Lock()
                conn.Open()
                tran = clsDB.BeginTran(conn)
                If (clsFc.InsertIportNumber(IPORT_NUMBER, conn, tran) > 0) Then
                    If (clsFc.InsertSAP_INCOME(Booking_no, IPORT_NUMBER, CustomerCode, ZBABI_HD.Doc_Date, ZBABI_HD.Pstng_Date, ZBABI_HD.Bupla, ZBABI_HD.Header_Txt, ZBABI_BK.Gl_Account, ZBABI_BK.Amount, ZBABI_BK.Value_Date, ZBABI_BK.Item_Text, EX_BUKRS, EX_BELNR, EX_GJAHR, Wht, "E", conn, tran) > 0) Then
                        For Each dr As SAP_IPORT.ZBAPI_CLEARING In BABI_CLEARINGTB
                            If (clsFc.InsertSAP_INCOME_CLEARING(IPORT_NUMBER, dr.Comp_Code, dr.Fisc_Year, dr.Ac_Doc_No, dr.Blart, dr.Whtamt, dr.Waers, conn, tran) < 1) Then
                                condition = False
                            End If
                        Next
                    Else
                        condition = False
                    End If
                    'If (ViewState("ALLOC_NMBR") & "" <> "") Then
                    '    If (clsFc.UPDATESale_OrderPay(Booking_no, ViewState("ALLOC_NMBR"), EX_BUKRS, EX_BELNR, EX_GJAHR, conn, tran) < 1) Then
                    '        condition = False
                    '    End If
                    'End If
                End If


                For Each dm As SAP_IPORT.BAPIRET1 In BABITable
                    If (clsFc.InsertSAP_Table_MESSAGE(IPORT_NUMBER, "Zbapi_Iport_Income_Payment", dm.Type, dm.Id, dm.Number, dm.Message, dm.Log_No, dm.Log_Msg_No, dm.Message_V1, dm.Message_V2, dm.Message_V3, dm.Message_V4, conn, tran) < 1) Then
                        condition = False
                    End If
                Next

                If (condition) Then
                    clsDB.CommitTran(tran)
                    'ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ชำระเงินเรียบร้อย ');", True)
                    ViewState("ALLOC_NMBR") = ""
                    Application.UnLock()
                    conn.Dispose()
                    ClassSAP.SAP_CLOSE(SAP_Data)
                    Return True
                Else
                    clsDB.RollBackTran(tran)
                    'ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('เกิดความผิดพลาด ');", True)
                    ViewState("ALLOC_NMBR") = ""
                    Application.UnLock()
                    conn.Dispose()
                    ClassSAP.SAP_CLOSE(SAP_Data)
                    Return False
                End If
            End If
        Else
            Return False
        End If

    End Function

    Private Sub LoadPaymentRecord()
        Dim IM_CUSTOMER As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Customer_no")
        Dim IM_COMPANY As String = "1001"
        Dim IM_DATE_FROM As String = Date.Now.ToString("yyyy", New CultureInfo("en-US")) & "0101"
        Dim IM_DATE_TO As String = Date.Now.ToString("yyyy", New CultureInfo("en-US")) & "1231"
        Dim EX_SUBRC As Integer = 0

        Dim ClassSAP As New Class_SAP
        Dim SAP_CLEAR As New SAP_IPORT.ZBAPI_AR_CLEARTable

        Dim SAP_Data As Object = ClassSAP.SAP_OPEN()
        SAP_Data.Zbapi_Iport_Ar_Clear_Item(IM_COMPANY, IM_CUSTOMER, IM_DATE_FROM, IM_DATE_TO, EX_SUBRC, SAP_CLEAR)
        ClassSAP.SAP_CLOSE(SAP_Data)
        If (SAP_CLEAR.Count > 0) Then
            Dim dt As DataTable = CreatePaymentRecord()
            For Each dr As SAP_IPORT.ZBAPI_AR_CLEAR In SAP_CLEAR
                Dim dn As DataRow = dt.NewRow()
                dn.Item("BUKRS") = dr.Bukrs
                dn.Item("BELNR") = dr.Belnr
                dn.Item("GJAHR") = dr.Gjahr
                dn.Item("BUZEI") = dr.Buzei
                dn.Item("BILL_TO") = dr.Bill_To
                dn.Item("MWSKZ") = dr.Mwskz
                dn.Item("BLART") = dr.Blart
                dn.Item("DOC_DESC") = dr.Doc_Desc
                dn.Item("XBLNR") = dr.Xblnr
                dn.Item("BLDAT") = dr.Bldat
                dn.Item("DUEDT") = dr.Duedt
                dn.Item("WAERS") = dr.Waers
                dn.Item("BASMAT") = dr.Basmat
                dn.Item("VAT") = dr.Vat
                dn.Item("NETAMT") = dr.Netamt
                dn.Item("WHTAMT") = dr.Whtamt
                dn.Item("TEXT40") = dr.Text40
                dn.Item("CLEAR_DATE") = dr.Clear_Date
                dn.Item("CLR_DOC_NO") = dr.Clr_Doc_No
                dn.Item("ADV_YEAR") = dr.Adv_Year
                dn.Item("ADV_DOC_NO") = dr.Adv_Doc_No
                If (dr.Clr_Doc_No & "" = "") Then
                    dn.Item("ALLOC_NMBR") = dr.Adv_Doc_No
                Else
                    dn.Item("ALLOC_NMBR") = dr.Clr_Doc_No
                End If
                dt.Rows.Add(dn)
                dt.AcceptChanges()
            Next
            LabelAlertRecord.Visible = False
            ViewState("Record") = dt
            gridRecord.DataSource = dt
            gridRecord.DataBind()
        Else
            LabelAlertRecord.Visible = True
            LabelAlertRecord.Text = "ไม่พบประวัติรายการชำระเงิน"
        End If
    End Sub

    Private Function CreatePaymentRecord() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("BUKRS", GetType(String))
        dt.Columns.Add("BELNR", GetType(String))
        dt.Columns.Add("GJAHR", GetType(String))
        dt.Columns.Add("BUZEI", GetType(String))
        dt.Columns.Add("BILL_TO", GetType(String))
        dt.Columns.Add("MWSKZ", GetType(String))
        dt.Columns.Add("BLART", GetType(String))
        dt.Columns.Add("DOC_DESC", GetType(String))
        dt.Columns.Add("XBLNR", GetType(String))
        dt.Columns.Add("BLDAT", GetType(String))
        dt.Columns.Add("DUEDT", GetType(String))
        dt.Columns.Add("WAERS", GetType(String))
        dt.Columns.Add("BASMAT", GetType(String))
        dt.Columns.Add("VAT", GetType(String))
        dt.Columns.Add("NETAMT", GetType(String))
        dt.Columns.Add("WHTAMT", GetType(String))
        dt.Columns.Add("TEXT40", GetType(String))
        dt.Columns.Add("CLEAR_DATE", GetType(String))
        dt.Columns.Add("CLR_DOC_NO", GetType(String))
        dt.Columns.Add("ADV_YEAR", GetType(String))
        dt.Columns.Add("ADV_DOC_NO", GetType(String))
        dt.Columns.Add("ALLOC_NMBR", GetType(String))
        dt.AcceptChanges()
        Return dt
    End Function

    Private Sub btnLoadPayin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoadPayin.Click
        LoadPayment()
    End Sub

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "M")
        End If
    End Sub

    Private Sub gridCNDN_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridCNDN.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Try
                e.Row.Cells(3).Text = CInt(e.Row.Cells(3).Text)
                Dim dt As DataTable = clsGet.Get_Customer(e.Row.Cells(3).Text)
                If (dt.Rows.Count > 0) Then
                    e.Row.Cells(3).ToolTip = dt.Rows(0).Item("NAME1") & " " & dt.Rows(0).Item("NAME2") & " " & dt.Rows(0).Item("NAME3")
                End If
            Catch ex As Exception

            End Try
            Dim chk As CheckBox = CType(e.Row.FindControl("chkCNDN"), CheckBox)
            If (gridCNDN.DataKeys(e.Row.RowIndex).Values("Ship_Name") & "" = "_H") Or (gridCNDN.DataKeys(e.Row.RowIndex).Values("Ship_Name") & "" = "_F") Then
                chk.Visible = False
            Else
                chk.Visible = True
                Dim DUE As String = gridCNDN.DataKeys(e.Row.RowIndex).Values("DUEDT") & ""
                Try
                    Dim days As String = DUE.Substring(6, 2)
                    Dim Month As String = GetNameMonth(DUE.Substring(4, 2))
                    Dim Year As String = DUE.Substring(0, 4)
                    DUE = days & " " & Month & " " & Year
                    If (CDate(DUE) > Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))) Then
                        Dim DayCurrent As String = Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))
                        Dim Day As Integer = DateDiff(DateInterval.Day, CDate(DayCurrent), CDate(DUE))

                        e.Row.Cells(12).Text = "NOT DUE"
                        e.Row.Cells(13).Text = "-" & Day
                    ElseIf (CDate(DUE) < Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))) Then
                        Dim DayCurrent As String = Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))
                        Dim Day As Integer = DateDiff(DateInterval.Day, CDate(DUE), CDate(DayCurrent))

                        e.Row.Cells(12).Text = "OVER DUE"
                        e.Row.Cells(13).Text = Day
                    Else
                        e.Row.Cells(12).Text = "DUE"
                        e.Row.Cells(13).Text = "0"
                    End If

                Catch ex As Exception

                End Try
            End If
            If (gridCNDN.DataKeys(e.Row.RowIndex).Values("Ship_Name") & "" = "") Then
                chk.Visible = False
                e.Row.BackColor = Drawing.Color.White
            End If
            Try
                e.Row.Cells(9).Text = FormatNumber(CDbl(e.Row.Cells(7).Text) + CDbl(e.Row.Cells(8).Text), 2)
            Catch ex As Exception

            End Try
        ElseIf (e.Row.RowType = DataControlRowType.Footer) Then
            e.Row.Cells(1).Text = "NET Amount"
            e.Row.Cells(7).Text = "0"
            e.Row.Cells(8).Text = "0"
            e.Row.Cells(9).Text = "0"
            e.Row.Cells(10).Text = "0"
            lbMoneyCNDN.Text = "0"
        End If
    End Sub

    Private Sub gridDefferred_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridDefferred.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Try
                e.Row.Cells(3).Text = CInt(e.Row.Cells(3).Text)
                Dim dt As DataTable = clsGet.Get_Customer(e.Row.Cells(3).Text)
                If (dt.Rows.Count > 0) Then
                    e.Row.Cells(3).ToolTip = dt.Rows(0).Item("NAME1") & " " & dt.Rows(0).Item("NAME2") & " " & dt.Rows(0).Item("NAME3")
                End If
            Catch ex As Exception

            End Try
            Dim chk As CheckBox = CType(e.Row.FindControl("chkCNDN"), CheckBox)
            If (gridDefferred.DataKeys(e.Row.RowIndex).Values("Ship_Name") & "" = "_H") Or (gridDefferred.DataKeys(e.Row.RowIndex).Values("Ship_Name") & "" = "_F") Then
                chk.Visible = False
            Else
                chk.Visible = True
                Dim DUE As String = gridDefferred.DataKeys(e.Row.RowIndex).Values("DUEDT") & ""
                Try
                    Dim days As String = DUE.Substring(6, 2)
                    Dim Month As String = GetNameMonth(DUE.Substring(4, 2))
                    Dim Year As String = DUE.Substring(0, 4)
                    DUE = days & " " & Month & " " & Year
                    If (CDate(DUE) > Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))) Then
                        Dim DayCurrent As String = Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))
                        Dim Day As Integer = DateDiff(DateInterval.Day, CDate(DayCurrent), CDate(DUE))

                        e.Row.Cells(12).Text = "NOT DUE"
                        e.Row.Cells(13).Text = "-" & Day
                    ElseIf (CDate(DUE) < Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))) Then
                        Dim DayCurrent As String = Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))
                        Dim Day As Integer = DateDiff(DateInterval.Day, CDate(DUE), CDate(DayCurrent))

                        e.Row.Cells(12).Text = "OVER DUE"
                        e.Row.Cells(13).Text = Day
                    Else
                        e.Row.Cells(12).Text = "DUE"
                        e.Row.Cells(13).Text = "0"
                    End If

                Catch ex As Exception

                End Try
            End If
            If (gridDefferred.DataKeys(e.Row.RowIndex).Values("Ship_Name") & "" = "") Then
                chk.Visible = False
                e.Row.BackColor = Drawing.Color.White
            End If
            Try
                e.Row.Cells(9).Text = FormatNumber(CDbl(e.Row.Cells(7).Text) + CDbl(e.Row.Cells(8).Text), 2)
            Catch ex As Exception

            End Try

        ElseIf (e.Row.RowType = DataControlRowType.Footer) Then
            e.Row.Cells(1).Text = "NET Amount"
            e.Row.Cells(7).Text = "0"
            e.Row.Cells(8).Text = "0"
            e.Row.Cells(9).Text = "0"
            e.Row.Cells(10).Text = "0"
            lbMoneyDeferred.Text = "0"
        End If
    End Sub

    Private Function GetNameMonth(ByVal Month As String) As String
        Try
            Select Case (CInt(Month).ToString("00"))
                Case "01"
                    Return "Jan"
                Case "02"
                    Return "Feb"
                Case "03"
                    Return "Mar"
                Case "04"
                    Return "Apr"
                Case "05"
                    Return "May"
                Case "06"
                    Return "Jun"
                Case "07"
                    Return "Jul"
                Case "08"
                    Return "Aug"
                Case "09"
                    Return "Sep"
                Case "10"
                    Return "Oct"
                Case "11"
                    Return "Nov"
                Case "12"
                    Return "Dec"
                Case Else
                    Return ""
            End Select
        Catch ex As Exception
            Return Month
        End Try

    End Function

    Private Sub ddlBankOX_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBankOX.SelectedIndexChanged
        If (ddlBankOX.SelectedValue & "" = "KBANK") Then
            With ddlAccountOX
                .Items.Clear()
                .ClearSelection()
                .DataTextField = "Account"
                .DataValueField = "Account"
                Dim customer As Integer = 0
                Try
                    customer = CInt(CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Customer_no"))
                Catch ex As Exception
                End Try
                Dim dt As DataTable = GetBookingAccount(customer)
                .DataSource = dt
                .DataBind()
                If dt.Rows.Count > 0 Then
                    btnPayOX.Visible = True
                End If
            End With
        Else
            ddlAccountOX.Items.Clear()
            btnPayOX.Visible = False
        End If
    End Sub

    Private Sub ddlBankDS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBankDS.SelectedIndexChanged
        If (ddlBankDS.SelectedValue & "" = "KBANK") Then
            With ddlAccountDS
                .Items.Clear()
                .ClearSelection()
                .DataTextField = "Account"
                .DataValueField = "Account"
                Dim customer As Integer = 0
                Try
                    customer = CInt(CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Customer_no"))
                Catch ex As Exception
                End Try
                Dim dt As DataTable = GetBookingAccount(customer)
                .DataSource = dt
                .DataBind()
                If dt.Rows.Count > 0 Then
                    btnPayDS.Visible = True
                End If
            End With
        Else
            ddlAccountDS.Items.Clear()
            btnPayDS.Visible = False
        End If
    End Sub

    Private Function GetBookingAccount(ByVal CustomerCode As String) As DataTable
        Dim ws As New WS_BANK.Service
        Dim Header As New WS_BANK.BankAccRequestHeader
        Dim bankAccount As New WS_BANK.BankAccRequestData()
        Dim RQ As New WS_BANK.BankAccRequestMessage()
        Dim RC(0) As WS_BANK.BankAccRequestCustomer

        Header.sponsorCode = "IRPC3"
        Header.bankCode = "004"
        Header.totalCustomerCode = 1

        RC(0) = New WS_BANK.BankAccRequestCustomer
        RC(0).customerCode = CustomerCode

        bankAccount.bankAccRequestHeader = Header
        bankAccount.bankAccRequestCustomer = RC

        RQ.operation = "BANK_ACCOUNT"
        RQ.bankAccRequestData = bankAccount

        Dim RS As New WS_BANK.BankAccResponseMessage
        Dim dt As New DataTable
        dt.Columns.Add("Account", GetType(String))
        dt.AcceptChanges()

        Try
            RS = ws.InvokeBooking("irpc_escf", "pwd12345", "https://203.147.52.228/ESCFWS/services/BankAccountService?wsdl", RQ, "w.ongarj", "Kun123456", "go2net2.irpc.in.th", 8080)

            If Not (RS.bankAccResponseData.bankAccResponseCustomer(0).accounts Is Nothing) Then
                For i As Integer = 0 To RS.bankAccResponseData.bankAccResponseCustomer(0).accounts.Length - 1
                    If (RS.bankAccResponseData.bankAccResponseCustomer(0).accounts(i).bankAccountNo <> "") Then
                        Dim dr As DataRow = dt.NewRow
                        dr.Item("Account") = RS.bankAccResponseData.bankAccResponseCustomer(0).accounts(i).bankAccountNo
                        dt.Rows.Add(dr)
                        dt.AcceptChanges()
                    End If
                Next
            End If
        Catch ex As Exception
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "  alert('ไม่สามารถทำการเชื่อมต่อธนาคารได้ !!');", True)
        End Try

        Return dt
    End Function

    Private Sub gridRecord_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridRecord.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Try
                e.Row.Cells(1).Text = CInt(e.Row.Cells(1).Text)
                Dim dt As DataTable = clsGet.Get_Customer(e.Row.Cells(1).Text)
                If (dt.Rows.Count > 0) Then
                    e.Row.Cells(1).ToolTip = dt.Rows(0).Item("NAME1") & " " & dt.Rows(0).Item("NAME2") & " " & dt.Rows(0).Item("NAME3")
                End If
            Catch ex As Exception

            End Try
            Try
                e.Row.Cells(8).Text = FormatNumber(CDbl(e.Row.Cells(6).Text) + CDbl(e.Row.Cells(7).Text), 2)
            Catch ex As Exception

            End Try
        End If
    End Sub
End Class